package com.livegoods.service.impl;

import com.livegoods.pojo.Banner;
import com.livegoods.service.BannerService;
import com.livegoods.vo.LiveGoodsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BannerServiceImpl implements BannerService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Value("${fastdfs.nginx.host}")
    private String nginxHost;

    @Override
    public LiveGoodsResult getAllBanner() {

        //查询所有banner数据
        List<Banner> banners = mongoTemplate.find(new Query(), Banner.class);

        //封装前端数据
        List<String> paths=new ArrayList<>();
        for (Banner banner : banners) {
            paths.add(nginxHost+banner.getPath());
        }

        return LiveGoodsResult.resultsOk(paths);
    }
}
